# -*- coding:utf8 -*-

import pickle
import os
import gzip
import Image

from visualUtil import *
from matplotlib.pylab import *

class ParamDumpHelper:
    def __init__(self, dump_file):
        self.dump_file = dump_file

    def dump(self, params):
        dumped_params = self.get_params_from_file()
        dumped_params.append(params)
        self.params_to_file(dumped_params)

    def params_to_file(self, params):
        f = gzip.open(self.dump_file, 'wb')
        if len(params) > 20:
            params = params[10:]
        pickle.dump(params, f)
        f.close()

    def get_params_from_file(self):
        if os.path.exists(self.dump_file):
            f = gzip.open(self.dump_file, 'rb')
            dumped_params = pickle.load(f)
            f.close()
            return dumped_params
        return []

def show_weight(param_path):
    """
    :param j:当前层的filter数
    :param i:上一层的filter数
    :return:
    """
    PFHelper = ParamDumpHelper(param_path)
    exist_params = PFHelper.get_params_from_file()
    if len(exist_params) != 0:
        exist_params = exist_params[-1]
    #print (exist_params[8][0].get_value())[2]
    flag = 1
    for i in range(40):
        for j in range(40):
            subplot(40,40,flag)
<<<<<<< HEAD
            imshow((exist_params[2][0].get_value())[i][j])
            axis("off")
            flag += 1
    show()
    savefig("/home/eelab/wxm/data/tea/result/W_e20_l0001_p2.png")

if __name__ == '__main__':
    show_weight("/home/eelab/wxm/data/tea/result/param_e20_l0001_h160_spp")
=======
            imshow((exist_params[4][0].get_value())[i][j])
            axis("off")
            flag += 1
    show()
    savefig("C:\\Users\\wuxiaomin\\Desktop\\arobei\\new\\W_e50_0001.png")

if __name__ == '__main__':
    show_weight("C:\\Users\\wuxiaomin\\Desktop\\arobei\\new\\param_e50_0001_cpu")
>>>>>>> 8568c94926e3d0d8c2cb51272715f91c2e7295f8
